"""HAL extension/aggregation
"""
import halogen

from .hal import ClubSchema,MatchSchema

class ClubExtSchema(ClubSchema):
    attation = halogen.Attr()
    members = halogen.Attr()


class ClubsOfProvince(halogen.Schema):
    """Clubs of Province
    """
    province = halogen.Attr()
    data = halogen.Attr(
        halogen.types.List(ClubExtSchema)
    )
class ClubIndexSchema(halogen.Schema):
    self = halogen.Link(attr=lambda arg: '#self')
    clubs = halogen.Attr(
        halogen.types.List(ClubsOfProvince)
    ) 
    attation = halogen.Attr(
        halogen.types.List(ClubSchema)
    )
    join = halogen.Attr(
        halogen.types.List(ClubSchema)
    )





class TableWithRankSchema(halogen.Schema):
    """See hal.TableSchema

    Payload:
        <Table, rank>
    """
    self = halogen.Link(attr=lambda arg: '#self')
    leagueID = halogen.Attr(attr='Table.leagueid')
    clubID = halogen.Attr(attr='Table.clubid')
    played = halogen.Attr(attr='Table.played')
    points = halogen.Attr(attr='Table.points')
    wins = halogen.Attr(attr='Table.wins')
    draws = halogen.Attr(attr='Table.draws')
    losses = halogen.Attr(attr='Table.losses')
    goalScored = halogen.Attr(attr='Table.goalscored')
    goalAgainst = halogen.Attr(attr='Table.goalagainst')
    lastUpdated = halogen.Attr(
        attr_type=halogen.types.ISOUTCDateTime(),
        attr='Table.lastupdated'
    )
    rank = halogen.Attr(attr='rank')


class TableWithRankCollection(halogen.Schema):
    self = halogen.Link(attr=lambda arg: '#self')
    next = halogen.Link(attr=lambda arg: '#next')
    prev = halogen.Link(attr=lambda arg: '#prev')
    tables = halogen.Embedded(
        halogen.types.List(TableWithRankSchema)
    )

class el(halogen.Schema):
    groupName = halogen.Attr()
    data = halogen.Attr(
        halogen.types.List(TableWithRankSchema)
    )

class sl(halogen.Schema):
    name = halogen.Attr()
    data = halogen.Attr(
        halogen.types.List(MatchSchema)
    )

class x(halogen.Schema):
    Elimination = halogen.Attr(
        halogen.types.List(sl)
    )

    Scoreboard = halogen.Attr(
        halogen.types.List(el)
    )

class TableWithCupSchema(halogen.Schema):
    self = halogen.Link(attr=lambda arg: '#self')
    next = halogen.Link(attr=lambda arg: '#next')
    prev = halogen.Link(attr=lambda arg: '#prev')
    tables = halogen.Embedded(
        x
    )

class SpiritWithRankSchema(halogen.Schema):
    """See hal.SpiritSchema

    Payload:
        <Spirit, rank>
    """
    self = halogen.Link(attr=lambda arg: '#self')
    leagueID = halogen.Attr(attr='Spirit.leagueid')
    clubID = halogen.Attr(attr='Spirit.clubid')
    points = halogen.Attr(attr='Spirit.points')
    proj01 = halogen.Attr(attr='Spirit.proj01')
    proj02 = halogen.Attr(attr='Spirit.proj02')
    proj03 = halogen.Attr(attr='Spirit.proj03')
    proj04 = halogen.Attr(attr='Spirit.proj04')
    proj05 = halogen.Attr(attr='Spirit.proj05')
    proj06 = halogen.Attr(attr='Spirit.proj06')
    proj07 = halogen.Attr(attr='Spirit.proj07')
    proj08 = halogen.Attr(attr='Spirit.proj08')
    proj09 = halogen.Attr(attr='Spirit.proj09')
    rank = halogen.Attr(attr='rank')


class SpiritWithRankCollection(halogen.Schema):
    self = halogen.Link(attr=lambda arg: '#self')
    next = halogen.Link(attr=lambda arg: '#next')
    prev = halogen.Link(attr=lambda arg: '#prev')
    spirits = halogen.Embedded(
        halogen.types.List(SpiritWithRankSchema)
    )


class PlayerRankSchema(halogen.Schema):
    """See hal.RankSchema

    Payload:
        <Rank, rank>
    """
    self = halogen.Link(attr=lambda arg: '#self')
    id = halogen.Attr(attr='Rank.id')
    leagueID = halogen.Attr(attr='Rank.leagueid')
    clubID = halogen.Attr(attr='Rank.clubid')
    userID = halogen.Attr(attr='Rank.userid')
    score = halogen.Attr(attr='Rank.score')
    ext = halogen.Attr(attr='Rank.ext')
    type = halogen.Attr(attr='Rank.type')
    lastUpdated = halogen.Attr(
        attr_type=halogen.types.ISOUTCDateTime(),
        attr='Rank.lastupdated'
    )
    rank = halogen.Attr(attr='rank')


class PlayerRankCollection(halogen.Schema):
    self = halogen.Link(attr=lambda arg: '#self')
    next = halogen.Link(attr=lambda arg: '#next')
    prev = halogen.Link(attr=lambda arg: '#prev')
    ranks = halogen.Embedded(
        halogen.types.List(PlayerRankSchema)
    )


class RankOfryCardSchema(halogen.Schema):
    """See hal.RankSchema

    Payload:
        <Red-Rank..., Yellow-Rank..., rank>
    """
    self = halogen.Link(attr=lambda arg: '#self')
    id = halogen.Attr('#id')
    leagueID = halogen.Attr(attr='Red.leagueid')
    clubID = halogen.Attr(attr='Red.clubid')
    userID = halogen.Attr(attr='Red.userid')
    red = halogen.Attr(attr='Red.score')
    yellow = halogen.Attr(attr='Yellow.score')
    type = halogen.Attr('#type')
    lastUpdated = halogen.Attr(
        attr_type=halogen.types.ISOUTCDateTime(),
        attr='Red.lastupdated'
    )
    rank = halogen.Attr(attr='rank')


class RankOfryCardCollection(halogen.Schema):
    self = halogen.Link(attr=lambda arg: '#self')
    next = halogen.Link(attr=lambda arg: '#next')
    prev = halogen.Link(attr=lambda arg: '#prev')
    ranks = halogen.Embedded(
        halogen.types.List(RankOfryCardSchema)
    )
